﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：公式设置
 */
var selectedRow;
var acceptClick;

var item;
var bootstrap = function ($, learun) {
    "use strict";
    var selectedRow = config.getParent(learun).selectedRow;
    var companyId = request("companyId");
    var ztId = request("ztId");
    var keyValue = request("keyValue");

    var page = {
        init: function () {
            page.inittree();
            page.bind();
        },
        bind: function () {
            $("input[name='btn_operate']").click(function () {
                var btn_operate = $("input[name='btn_operate']:checked").val();
                if (btn_operate == 'add') {
                    $("#sp_operate").html("统加金额");
                } else if (btn_operate == 'reduce') {
                    $("#sp_operate").html("统减金额");
                } else if (btn_operate == 'multipe') {
                    $("#sp_operate").html("统乘金额");
                } else if (btn_operate == 'divide') {
                    $("#sp_operate").html("统除金额");
                } else if (btn_operate == 'set') {
                    $("#sp_operate").html("统置金额");
                }
            });
        },
        inittree: function () {
            if (companyId != "" && ztId != '') {
                $('#itemTree').lrtree({
                    url: config.base_server() + 'gzitems/dropdownlist?companyId=' + companyId + '&ztId=' + ztId + '&showCheck=' + 0 + '&access_token=' + config.getToken().access_token,
                    param: {},
                    nodeDbClick: page.treeNodeDbClick
                });
            }
            if (!!selectedRow) {
                $('#sp_item').html(selectedRow.name);
            }
        },
        treeNodeDbClick: function (node) {
            item = node;
        }
    };

    // 保存数据
    acceptClick = function (callBack) {
        var money = $('#money').val();
        if (money == '') {
            learun.alert.warning("请输入正确的金额");
            return;
        }
        var currentItem = $('#itemTree').lrtreeSet("currentItem");
        if (!currentItem) {
            learun.alert.warning("请选择要调整的款项");
            return;
        }
        var postData = $('#form').lrGetFormData();
        postData.itemId = currentItem.id;
        postData.money = money;
        postData.operate = postData.btn_operate;

        learun.layerConfirm('您确认对款项【' + currentItem.text + '】执行批量修改吗？请注意一旦修改将不可恢复！', function (res) {
            if (res) {
                learun.postForm(config.base_server() + 'gzrecordsalarys/edit?companyId=' + companyId + '&ztId=' + ztId + '&itemId=' + postData.itemId + '&money=' + postData.money + '&operate=' + postData.operate + '&access_token=' + config.getToken().access_token, JSON.stringify(postData), function (res) {
                    // 保存成功后才回调
                    if (!!callBack) {
                        callBack();
                    }
                });
            }
        });


    };

    page.init();
}


